import { Injectable } from '@angular/core';
import { Jsonp, Http } from '@angular/http';

@Injectable()

export class ManhuaImageProvider {

    constructor(private http: Http, private jsonp: Jsonp) { }

    // http://www.1kkk.com/ch9-568863/chapterfun.ashx?cid=568863&page=3&key=&language=1&gtk=6&_cid=568863&_mid=39084&_dt=2018-02-05+14%3A53%3A35&_sign=d96258c16713c8f0825405842e880d6b

    getParam(manhua) {

        let domain = manhua['domain'], json = {};
        switch (domain) {
            case 'www.1kkk.com':
            case 'http://www.1kkk.com':
                json['url'] = manhua['cur_chapter']['href'];

                return this.get1kkkParam(json);     

            case 'manhua.dmzj.com':
            case 'http://manhua.dmzj.com':
                json['url'] = manhua['cur_chapter']['href'];

                return this.getdmzjParam(json);
               
            case 'http://www.manhuagui.com':
                json['url'] = manhua['cur_chapter']['href'];

                return this.getmhgParam(json);
            default:
                break;
        }
    }

    getImage(manhua, data) {
        let domain = manhua['domain'], json = {};

        switch (domain) {
            case 'www.1kkk.com':
            case 'http://www.1kkk.com':
                json = {
                    Referer: manhua.cur_chapter.href,
                    url: manhua.cur_chapter.href + "chapterfun.ashx",
                    data: data
                };
                return this.get1kkkImage(json);
         
            case '':
                break;
            default:
                break;
        }
    }

    /**
     * 
     * @param url url
     * @param param  {href,page}
     */
    get1kkkImage(param) {
        // http://www.1kkk.com/ch1-572865/history.ashx?cid=572865&mid=40421&page=2&uid=0&language=1
        return this.http.get('/api/manhua/proxy', { search: param });
    }

    get1kkkParam(param) {
        return this.http.get('/api/manhua/get1kkkImageParam', { search: param });
    }

    // 直接返回图片url连接
    getdmzjParam(param) {
        return this.http.get('/api/manhua/getdmzjImages', { search: param });
    }

    // 直接返回图片url连接
    getmhgParam(param) {
        return this.http.get('/api/manhua/getmhgImages', { search: param });
    }

    // getdmzjParam(url){
    //     return this.http.get(url);
    // }
}